package com.fnzx.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.fnzx.dao.ProjectUserRelationDao;
import com.fnzx.entity.ProjectUserRelationEntity;
import com.fnzx.entity.vo.ScoreVo;
import com.fnzx.service.ProjectUserRelationService;
import com.fnzx.util.PageUtils;
import com.fnzx.util.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import javax.annotation.Resource;


@Service("projectUserRelationService")
public class ProjectUserRelationServiceImpl extends ServiceImpl<ProjectUserRelationDao, ProjectUserRelationEntity> implements ProjectUserRelationService {

    @Resource
    ProjectUserRelationDao projectUserRelationDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<ProjectUserRelationEntity> page = this.page(
                new Query<ProjectUserRelationEntity>().getPage(params),
                new QueryWrapper<ProjectUserRelationEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public List<ScoreVo> info(String projectId) {
        List<ScoreVo> scoreVo = projectUserRelationDao.info(projectId);
        return scoreVo;
    }

    @Override
    public void removeByProjectId(Long projectId) {
        QueryWrapper<ProjectUserRelationEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("project_id", projectId);
        List<ProjectUserRelationEntity> projectUserRelationEntities = projectUserRelationDao.selectList(queryWrapper);
        List<Long> list = new ArrayList<>();
        for (ProjectUserRelationEntity projectUserRelationEntity : projectUserRelationEntities) {
            list.add(projectUserRelationEntity.getId());
        }
        projectUserRelationDao.deleteBatchIds(list);
    }

}